#include <iostream>
#include <unordered_map>
using namespace std;

struct Name
{
	string name;
	int point;
} a[1001];

int main()
{
	int n;
	cin >> n;
	unordered_map <string, int> M;
	unordered_map <string, bool> MJ;
	for (int i = 0; i != n; ++i) {
		cin >> a[i].name >> a[i].point;
		M[a[i].name] += a[i].point;
	}
	Name max;
	max.point = 0;
	for (unordered_map <string, int>::const_iterator it = M.cbegin();
			it != M.cend(); ++it) {
		if (it->second > max.point) {
			max.name = it->first;
			max.point = it->second;
		}
	}
	for (unordered_map <string, int>::const_iterator it = M.cbegin();
			it != M.cend(); ++it)
		if (it->second == max.point) MJ[it->first] = true;
	M.clear();
	for (int i = 0; i != n; ++i) {
		M[a[i].name] += a[i].point;
		if (MJ[a[i].name] && M[a[i].name] >= max.point) {
			cout << a[i].name << endl;
			return 0;
		}
	}
}
